package com.wh.common.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wh.basic.vo.AjaxResult;
import com.wh.common.dto.NoticeDto;
import com.wh.common.pojo.Notice;
import com.wh.common.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author 1
 * @since 2024-06-21 星期五 18:28:08
 */
@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Autowired
    public NoticeService noticeService;

    /**
     * 接口：添加
     * @param notice 传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping("/addNotice")
    public AjaxResult add(@RequestBody Notice notice) {
        noticeService.add(notice);
        return new AjaxResult();
    }
    /**
     * 接口：修改
     *
     * @param notice 传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping("/upd")
    public AjaxResult update(@RequestBody Notice notice) {
        noticeService.updNotice(notice);
        return new AjaxResult();
    }

    /**
     * 接口：删除
     *
     * @param noticeId
     * @return AjaxResult 响应给前端
     */
    @DeleteMapping(value = "/del/{id}")
    public AjaxResult del(@PathVariable("id") Integer noticeId) {
        noticeService.deleByid(noticeId);
        return new AjaxResult();
    }


    /**
     * 接口：分页查询或高级查询
     *
     * @param noticeDto 查询对象
     * @return IPage<Task> 分页对象
     */
    
    @PostMapping("/findAllNoticeInfo")
    public IPage<Notice> findByPage(@RequestBody NoticeDto noticeDto) {
        return noticeService.findByPage(noticeDto);
    }

    @PutMapping("/createTop/{id}")
    public AjaxResult createTop(@PathVariable("id") Integer id) {
        noticeService.createTop(id);
        return new AjaxResult();
    }
    @PutMapping("/downTop/{id}")
    public AjaxResult downTop(@PathVariable("id") Integer id) {
        noticeService.downTop(id);
        return new AjaxResult();
    }

    /**
     * 初始化获取数据
     * @return
     */
//    @GetMapping("/data")
//    public AjaxResult getData() throws IOException {
//        String noticeText= noticeService.getTopData();
//        System.err.println(noticeText);
//        return new AjaxResult().setMessage(noticeText);
//    }



}
